export const IS_BROWSER =
  typeof window !== "undefined" && typeof window.document !== "undefined";
export const WINDOW = IS_BROWSER ? window : {};
export const IS_TOUCH_DEVICE =
  IS_BROWSER && window.document.documentElement
    ? "ontouchstart" in window.document.documentElement
    : false;
export const HAS_POINTER_EVENT = IS_BROWSER ? "PointerEvent" in WINDOW : false;

export const NAMESPACE = "star";

// className
export const CLASS_RESIZE_BOX = `${NAMESPACE}-resize-box`;

// Actions

export const ACTION_ALL: ActionType = "all";
export const ACTION_CROP: ActionType = "crop";
export const ACTION_MOVE: ActionType = "move";
export const ACTION_ZOOM: ActionType = "zoom";
export const ACTION_EAST: ActionType = "e";
export const ACTION_WEST: ActionType = "w";
export const ACTION_SOUTH: ActionType = "s";
export const ACTION_NORTH: ActionType = "n";
export const ACTION_NORTH_EAST: ActionType = "ne";
export const ACTION_NORTH_WEST: ActionType = "nw";
export const ACTION_SOUTH_EAST: ActionType = "se";
export const ACTION_SOUTH_WEST: ActionType = "sw";

export type ActionType =
  | "all"
  | "crop"
  | "move"
  | "zoom"
  | "e"
  | "w"
  | "s"
  | "n"
  | "ne"
  | "nw"
  | "se"
  | "sw";

// Events
export const EVENT_CROP = "crop";
export const EVENT_CROP_END = "cropend";
export const EVENT_CROP_MOVE = "cropmove";
export const EVENT_CROP_START = "cropstart";
export const EVENT_DBLCLICK = "dblclick";
export const EVENT_TOUCH_START = IS_TOUCH_DEVICE ? "touchstart" : "mousedown";
export const EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? "touchmove" : "mousemove";
export const EVENT_TOUCH_END = IS_TOUCH_DEVICE
  ? "touchend touchcancel"
  : "mouseup";
export const EVENT_POINTER_DOWN = HAS_POINTER_EVENT
  ? "pointerdown"
  : EVENT_TOUCH_START;
export const EVENT_POINTER_MOVE = HAS_POINTER_EVENT
  ? "pointermove"
  : EVENT_TOUCH_MOVE;
export const EVENT_POINTER_UP = HAS_POINTER_EVENT
  ? "pointerup pointercancel"
  : EVENT_TOUCH_END;
export const EVENT_READY = "ready";
export const EVENT_RESIZE = "resize";
export const EVENT_WHEEL = "wheel";
export const EVENT_ZOOM = "zoom";
